<%-- 
	readMe:
	1.只供前台页面（除会员中心）分页调用
	2.不再使用js用form.submit的方式进行，使用直接url超链接方式

--%>
<%@ tag body-content="empty"%>
<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ tag import="com.probiz.estore.Constants" %>
<%@ attribute name="target" type="java.lang.String" required="false" description="分页提交到的网址，一般情况下默认是当前pagingUrl，一般不需要指定该参数"%>

<c:if test="${sc.totalPageCount>0}">
	<%
		String pagingUrl = target;
		if(null == pagingUrl){
			pagingUrl=(String)request.getAttribute(Constants.PRE_URL);
		}
		//有一定顺序
		pagingUrl = pagingUrl.replaceAll("&PrmPageNo=[0-9]\\d*","");
		pagingUrl = pagingUrl.replaceAll("\\?PrmPageNo=[0-9]\\d*&","?");		
		pagingUrl = pagingUrl.replaceAll("\\?PrmPageNo=[0-9]\\d*","");
		if(pagingUrl.indexOf("?")!=-1){
			jspContext.setAttribute("pagingUrl",pagingUrl+"&PrmPageNo");	
		}else{
			jspContext.setAttribute("pagingUrl",pagingUrl+"?PrmPageNo");
		}	
	%>
	<div class=pagination>

		<c:if test="${sc.totalPageCount>1}">
			<c:choose>
				<c:when test="${sc.pageNo<=1}">
					<a  class="no_first" title='<fmt:message key="list.paging.goto1"/>' ></a>
				</c:when>
				<c:otherwise>
					<a  href="${pagingUrl}=1" class="first" title='<fmt:message key="list.paging.goto1"/>' ></a>
				</c:otherwise>
			</c:choose>
			
			<c:choose>
				<c:when test="${sc.pageNo<=1}">
					<a  class="no_prev1" title='<fmt:message key="list.paging.prev"/>'></a>
				</c:when>
				<c:otherwise>
					<a href="<c:choose><c:when test="${(sc.pageNo-1) lt 1}">${pagingUrl}=1</c:when><c:otherwise>${pagingUrl}=${sc.pageNo-1}</c:otherwise></c:choose>" class="prev1" title='<fmt:message key="list.paging.prev"/>'></a>
				</c:otherwise>
			</c:choose>

			<c:set var="minPager"
				value="${(sc.totalPageCount-sc.pageNo>=4)?(sc.pageNo >= 5 ? sc.pageNo - 4
                      : 1):(sc.pageNo >= (5 + 4 - sc.totalPageCount + sc.pageNo) ? (sc.pageNo
                              - 8 + sc.totalPageCount - sc.pageNo) : 1)}" />
			<c:set var="maxPager"
				value="${(minPager + 8 > sc.totalPageCount) ? sc.totalPageCount : (minPager + 8)}" />
			<c:forEach var="idx" begin="${minPager}" end="${maxPager}" step="1">
				<c:if test="${sc.pageNo!=idx}">
					<a href="${pagingUrl}=${idx}" title="<fmt:message key="list.paging.gotoN"><fmt:param>${idx}</fmt:param></fmt:message>">${idx}</a>
				</c:if>
				<c:if test="${sc.pageNo==idx}">
					<a class="curr"> ${idx} </a>
				</c:if>
			</c:forEach>

			<c:choose>
				<c:when test="${sc.pageNo>=sc.totalPageCount}">
					<a  class="no_next2" title='<fmt:message key="list.paging.next"/>' ></a>
				</c:when>
				<c:otherwise>
					<a href="<c:choose><c:when test="${(sc.pageNo+1) gt sc.totalPageCount}">${pagingUrl}=${sc.totalPageCount}</c:when><c:otherwise>${pagingUrl}=${sc.pageNo+1}</c:otherwise></c:choose>" class="next2" title='<fmt:message key="list.paging.next"/>'></a>
				</c:otherwise>
			</c:choose>

			<c:choose>
				<c:when test="${sc.pageNo>=sc.totalPageCount}">
					<a class="no_last" title='<fmt:message key="list.paging.gotoEnd"/>'></a>
				</c:when>
				<c:otherwise>
					<a href="${pagingUrl}=${sc.totalPageCount}" class="last" title='<fmt:message key="list.paging.gotoEnd"/>'></a>
				</c:otherwise>
			</c:choose>
			
			<input type="text" style="width:40px" class="inputtxt" value="${sc.pageNo}" id="pager_input" />
			<a href="javascript:void(0)"  class="goto" onclick="gotoPage($j('#pager_input').val());return false;"></a>

		</c:if>

	</div>
	<input type="hidden" id="PrmPageNo" name="PrmPageNo" value="${sc.pageNo}">
	
	
</c:if>

<script type="text/javascript">	
$j(document).ready(function(){
	$j('#pager_input').keyup(function(event){
		if( event.keyCode == 13 ){
		 	gotoPage($j(this).val());
	  	}
	  	return false;
	});

});
	
function gotoPage(pageNo) {
	if(isNaN(pageNo) || pageNo <= 0){
		alert("请填写正整数！");
		return false;
	}
	$j("#PrmPageNo").val(pageNo);
	location.href = "${pagingUrl}="+pageNo;
	return false;
}

</script>	



